home *** CD-ROM | disk | FTP | other *** search
- /* VINC */
- /* */
- /* This is a C language subroutine to display a screen and */
- /* get users data entered on it into a file as ASCII text. */
- /* */
-
- #define NULL '\000'
- #define BLANK '\040'
- #define ESCAPE '\033'
- #include <stdio.h>
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- unsigned char scrname[67],buffer[1025],dflname[67],cdata[82];
- unsigned char dataname[67],filename[67],colors[82];
- unsigned char dattr[101],dcolors[101][16];
- int dcol[101],dline[101],dlen[101];
- int filein,i,j,count,k;
-
- strcpy(filename,argv[1]);
- strcpy(scrname,filename);
- strcat(scrname,".scr");
- strcpy(dflname,filename);
- strcat(dflname,".dfd");
- strcpy(dataname,filename);
- strcat(dataname,".dat");
-
- ansicol("low white black",buffer) ;
- ansimvc(1,1);
- printf("%s",buffer) ;
-
- /* display user screen */
- if ((filein=open(scrname,AREAD)) < 1)
- abort("\nERROR READING <%s> ",scrname) ;
- for(i=1;i<=24;i++)
- {
- if ((j=read(filein,buffer,1024)) == 0) break;
- buffer[j-1] = NULL ;
- ansimvc(i,1) ;
- for(k=0;k<=strlen(buffer)-1;k++)
- if (buffer[k] == '@') printf(" ");
- else printf("%c",buffer[k]);
- /***** printf("%s",buffer);****/
- }
- close(filein) ;
-
- /* load dfd (data field definitions */
- count = -1;
- if ((filein=open(dflname,AREAD)) < 1)
- abort("\nERROR READING <%s> ",dflname) ;
- for(i=1;i<=100;i++)
- {
- if ((j=read(filein,buffer,1024)) == 0) break;
- buffer[j-1] = NULL ;
- for(j=0,k=0;j<=3;j++)
- {
- if ((buffer[j] == NULL) || (buffer[j] == BLANK))break;
- cdata[k++]=buffer[j];
- buffer[j] = BLANK ;
- }
- cdata[k]=NULL ;
- dline[++count] = atoi(cdata) ;
-
- leftadj(buffer);
- for(j=0,k=0;j<=3;j++)
- {
- if ((buffer[j] == NULL) || (buffer[j] == BLANK))break;
- cdata[k++]=buffer[j];
- buffer[j] = BLANK ;
- }
- cdata[k]=NULL ;
- dcol[count] = atoi(cdata) ;
-
- leftadj(buffer);
- for(j=0,k=0;j<=3;j++)
- {
- if ((buffer[j] == NULL) || (buffer[j] == BLANK))break;
- cdata[k++]=buffer[j];
- buffer[j] = BLANK ;
- }
- cdata[k]=NULL ;
- dlen[count] = atoi(cdata) ;
-
- leftadj(buffer);
- for(j=0,k=0;j<=3;j++)
- {
- if ((buffer[j] == NULL) || (buffer[j] == BLANK))break;
- cdata[k++]=buffer[j];
- buffer[j] = BLANK ;
- }
- cdata[k]=NULL ;
- k = atoi(cdata) ;
- dattr[count] = k;
- makecol(dattr[count],colors);
- ansicol(colors,buffer);
- strcpy(dcolors[count],buffer) ;
- ansimvc(dline[count],dcol[count]);
- printf("%s",buffer);
- for(k=1;k<=dlen[count];k++)
- printf(" ");
- }
- close(filein) ;
-
- /* get users data typed in */
-
- if ((filein=creat(dataname,AWRITE)) < 1)
- abort("\nERROR CREATING <%s> ",dataname) ;
- for (i=0;i<=count;i++)
- {
- ansimvc(dline[i],dcol[i]);
- getdata(dline[i],dcol[i],dlen[i],dcolors[i],cdata) ;
- write(filein,cdata,strlen(cdata));
- }
- close(filein) ;
- ansicol("low white black",buffer) ;
- ansimvc(1,1);
- printf("%s",buffer) ;
- return(0) ;
- }
-
- /* ANSIMVC - MOVE CURSOR TO LINE AND COLUMN */
- ansimvc(line,col)
- int line,col ;
- {
- unsigned char cline[3],ccol[3];
-
- itoa(line,cline);
- itoa(col,ccol);
- printf("%c[%s;%sH",ESCAPE,cline,ccol);
- return(0) ;
- }
-
- /* ANSICOL - convert string of color specs to escape sequences */
- ansicol(inbuf,colors)
- unsigned char inbuf[],colors[];
- {
- int i,j ;
- unsigned char buffer[256],colors1[30],colors2[30];
- unsigned char colors0[30],colbuf[30];
-
- for (i=0;i<=strlen(inbuf)-1;buffer[i]=toupper(inbuf[i]),i++);
- buffer[i]=NULL;
- colors[0] = NULL ;
- colors0[0] = NULL ;
- colors1[0] = NULL ;
- colors2[0] = NULL ;
- colbuf[0] = NULL ;
-
-
- /* check for monochrome verbs first */
- inten: ;
- leftadj(buffer);
- if (strncmp(buffer,"LOW",3) == 0)
- {
- for(i=0;i<=2;buffer[i++]=BLANK) ;
- sprintf(colors0,"%c%s",ESCAPE,"[0m");
- strcat(colbuf,colors0); goto inten;
- }
- else
- if (strncmp(buffer,"HIGH",4) == 0)
- {
- for(i=0;i<=3;buffer[i++]=BLANK) ;
- sprintf(colors0,"%c%s",ESCAPE,"[1m");
- strcat(colbuf,colors0); goto inten;
- }
- else
- if (strncmp(buffer,"UNDER",5) == 0)
- {
- for(i=0;i<=4;buffer[i++]=BLANK) ;
- sprintf(colors0,"%c%s",ESCAPE,"[4m");
- strcat(colbuf,colors0); goto inten;
- }
- else
- if (strncmp(buffer,"BLINK",5) == 0)
- {
- for(i=0;i<=4;buffer[i++]=BLANK) ;
- sprintf(colors0,"%c%s",ESCAPE,"[5m");
- strcat(colbuf,colors0); goto inten;
- }
- else
- if (strncmp(buffer,"REVERSE",7) == 0)
- {
- for(i=0;i<=6;buffer[i++]=BLANK) ;
- sprintf(colors0,"%c%s",ESCAPE,"[7m");
- strcat(colbuf,colors0); goto inten;
- }
- else
- if (strncmp(buffer,"DARK",4) == 0)
- {
- for(i=0;i<=3;buffer[i++]=BLANK) ;
- sprintf(colors0,"%c%s",ESCAPE,"[8m");
- strcat(colbuf,colors0); goto inten;
- }
- strcpy(colors0,colbuf) ;
-
- leftadj(buffer) ;
- if (buffer[0] == NULL) goto exitit;
-
- /* default to white on black if no colors supplied */
- sprintf(colors1,"%c%s",ESCAPE,"[37m");
- sprintf(colors2,"%c%s",ESCAPE,"[40m");
-
-
- /* real first color, not monochrome crt */
- if (strncmp(buffer,"BLACK",5) == 0)
- {
- for(i=0;i<=4;buffer[i++]=BLANK) ;
- sprintf(colors1,"%c%s",ESCAPE,"[30m");
- }
- else
- if (strncmp(buffer,"RED",3) == 0)
- {
- for(i=0;i<=2;buffer[i++]=BLANK) ;
- sprintf(colors1,"%c%s",ESCAPE,"[31m");
- }
- else
- if (strncmp(buffer,"GREEN",5) == 0)
- {
- for(i=0;i<=4;buffer[i++]=BLANK) ;
- sprintf(colors1,"%c%s",ESCAPE,"[32m");
- }
- else
- if (strncmp(buffer,"YELLOW",6) == 0)
- {
- for(i=0;i<=5;buffer[i++]=BLANK) ;
- sprintf(colors1,"%c%s",ESCAPE,"[33m");
- }
- else
- if (strncmp(buffer,"BLUE",4) == 0)
- {
- for(i=0;i<=3;buffer[i++]=BLANK) ;
- sprintf(colors1,"%c%s",ESCAPE,"[34m");
- }
- else
- if (strncmp(buffer,"MAGENTA",7) == 0)
- {
- for(i=0;i<=6;buffer[i++]=BLANK) ;
- sprintf(colors1,"%c%s",ESCAPE,"[35m");
- }
- else
- if (strncmp(buffer,"CYAN",4) == 0)
- {
- for(i=0;i<=3;buffer[i++]=BLANK) ;
- sprintf(colors1,"%c%s",ESCAPE,"[36m");
- }
- else
- if (strncmp(buffer,"WHITE",5) == 0)
- {
- for(i=0;i<=4;buffer[i++]=BLANK) ;
- sprintf(colors1,"%c%s",ESCAPE,"[37m");
- }
- else
- sprintf(colors1,"%c%s",ESCAPE,"[0m");
-
- leftadj(buffer) ;
- if (buffer[0] == NULL)
- {
- sprintf(colors2,"%c%s",ESCAPE,"[40m");
- goto exitit;
- }
-
- /* background colors */
- if (strncmp(buffer,"BLACK",5) == 0)
- {
- for(i=0;i<=4;buffer[i++]=BLANK) ;
- sprintf(colors2,"%c%s",ESCAPE,"[40m");
- }
- else
- if (strncmp(buffer,"RED",3) == 0)
- {
- for(i=0;i<=2;buffer[i++]=BLANK) ;
- sprintf(colors2,"%c%s",ESCAPE,"[41m");
- }
- else
- if (strncmp(buffer,"GREEN",5) == 0)
- {
- for(i=0;i<=4;buffer[i++]=BLANK) ;
- sprintf(colors2,"%c%s",ESCAPE,"[42m");
- }
- else
- if (strncmp(buffer,"YELLOW",6) == 0)
- {
- for(i=0;i<=5;buffer[i++]=BLANK) ;
- sprintf(colors2,"%c%s",ESCAPE,"[43m");
- }
- else
- if (strncmp(buffer,"BLUE",4) == 0)
- {
- for(i=0;i<=3;buffer[i++]=BLANK) ;
- sprintf(colors2,"%c%s",ESCAPE,"[44m");
- }
- else
- if (strncmp(buffer,"MAGENTA",7) == 0)
- {
- for(i=0;i<=3;buffer[i++]=BLANK) ;
- sprintf(colors2,"%c%s",ESCAPE,"[45m");
- }
- else
- if (strncmp(buffer,"CYAN",4) == 0)
- {
- for(i=0;i<=3;buffer[i++]=BLANK) ;
- sprintf(colors2,"%c%s",ESCAPE,"[46m");
- }
- else
- if (strncmp(buffer,"WHITE",5) == 0)
- {
- for(i=0;i<=4;buffer[i++]=BLANK) ;
- sprintf(colors2,"%c%s",ESCAPE,"[47m");
- }
-
- exitit: ;
- strcpy(colors,colors0) ;
- strcat(colors,colors1) ;
- strcat(colors,colors2) ;
-
- leftadj(buffer) ;
- if (buffer[0] != NULL) return(-1) ;
- else return(0) ;
- }
-
- ansicls()
- { printf("%c%s",'\033',"[2J") ; }
-
- /* MAKECOL */
- /* this function converts a IBM video ram attribute to a character */
- /* string of the correct attributes for use with the ansicol */
- /* function */
- makecol(attrib,colors)
- unsigned char attrib,colors[];
- {
- int i,j,back,fore,mod;
- unsigned char cback[30],cfore[30],cintens[30];
-
- i = attrib ;
- /***if (i > 127) i -= 128****/
- if (i > 127) i -= 128;
- i = i / 16;
- back = i;
- if (back == 0)
- strcpy(cback,"black"); else
- if (back == 1)
- strcpy(cback,"blue"); else
- if (back == 2)
- strcpy(cback,"green"); else
- if (back == 3)
- strcpy(cback,"cyan"); else
- if (back == 4)
- strcpy(cback,"red"); else
- if (back == 5)
- strcpy(cback,"magenta"); else
- if (back == 6)
- strcpy(cback,"yellow");
- else
- strcpy(cback,"white");
-
- cintens[0] = NULL ;
- mod = attrib % 16;
- fore = mod;
- if (fore < 8)
- strcpy(cintens,"low ");
- else
- strcpy(cintens,"high ");
-
- if ((fore == 0) || (fore == 8))
- strcpy(cfore,"black"); else
- if ((fore == 1) || (fore == 9))
- strcpy(cfore,"blue"); else
- if ((fore == 2) || (fore == 10))
- strcpy(cfore,"green"); else
- if ((fore == 3) || (fore == 11))
- strcpy(cfore,"cyan"); else
- if ((fore == 4) || (fore == 12))
- strcpy(cfore,"red"); else
- if ((fore == 5) || (fore == 13))
- strcpy(cfore,"magenta"); else
- if ((fore == 6) || (fore == 14))
- strcpy(cfore,"yellow");
- else
- strcpy(cfore,"white");
-
- /* special cases */
-
- if (( (attrib-9) % 16) == 0)
- strcat(cintens,"under ");
- if (( (attrib-1) % 16) == 0)
- strcat(cintens,"under ");
- if (attrib > 127)
- strcat(cintens,"blink ");
-
-
- strcpy(colors,cintens);
- strcat(colors,cfore);
- strcat(colors," ");
- strcat(colors,cback);
-
- return(0) ;
- } /* end of program */
-
- /* leftadj - left adjust to position zero */
- leftadj(s)
- unsigned char s[];
- {
- int i,j,started;
- started = 0 ;
- for(i=0,j=0;i<=32000;i++)
- {
- if (s[i] == NULL) break ;
- if (started)
- s[j++] = s[i];
- else
- if (s[i] != BLANK)
- {
- started = 1 ;
- s[j++] = s[i];
- }
- }
- s[j]= NULL ;
- }
-
- getdata(line,col,length,colors,cdata)
- int line,col,length;
- unsigned char cdata[],colors[];
- {
- fgets(cdata,length,stdin);
- return(0) ;
- }